﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ajayumi.develop.win32.Transport.Server.WinForm.Properties;
using System.IO;
using System.Windows.Forms;

namespace ajayumi.develop.win32.Transport.Server.WinForm
{
    /// <summary>
    /// 应用程序配置类，保存一些全局变量
    /// Author  : 黄乙冬
    /// Date    : 2011-08-29
    /// </summary>
    internal class AppConfig
    {
        private static string m_SaveDir = string.Empty;
        internal static string SaveDir
        {
            get { return AppConfig.m_SaveDir; }
            set { AppConfig.m_SaveDir = value; }
        }

        private static int m_BufferSize = 512;
        internal static int BufferSize
        {
            get { return AppConfig.m_BufferSize; }
            set { AppConfig.m_BufferSize = value; }
        }

        /// <summary>
        /// 初始化应用程序配置
        /// </summary>
        internal static void Init()
        {
            m_SaveDir = Settings.Default.SaveDir;
            if (string.IsNullOrEmpty(m_SaveDir))
            {
                string saveDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Received");
                if (!Directory.Exists(saveDir))
                { Directory.CreateDirectory(saveDir); }
                m_SaveDir = saveDir;
            }
            m_BufferSize = Settings.Default.BufferSize;
        }

        internal static void Save()
        {
            Settings.Default.SaveDir = m_SaveDir;
            Settings.Default.BufferSize = (int)m_BufferSize;
            Settings.Default.Save();
        }
    }
}
